package com.dataseek.iot.sys.controller;

import com.dataseek.iot.sys.entity.NotifyLog1;
import com.dataseek.iot.sys.service.NotifyLogService;
import com.dataseek.iot.sys.vo.NotifyLogVo1;
import com.dataseek.iot.toolikit.common.enums.RspStatusEnum;
import com.dataseek.iot.toolikit.common.response.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("**/notifyLog")
public class NotifyLogController {

    @Autowired
    private NotifyLogService notifyLogService;


    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public ResponseResult query(@RequestParam(value="page")  Integer page,
                                      @RequestParam(value="size")  Integer size,
                                      @RequestParam(value="userId", required = false) String userId,
                                      @RequestParam(value="status", required = false) String status) throws IOException {
        NotifyLogVo1 notifyLogVo1 = notifyLogService.queryAction(userId, status, page,size);
        return new ResponseResult(RspStatusEnum.SUCCESS.getCode(),"成功", notifyLogVo1);
    }


    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public ResponseResult insert(@RequestBody NotifyLog1 notifyLog1) throws IOException {
        notifyLogService.insertAction(notifyLog1);
        return new ResponseResult(RspStatusEnum.SUCCESS.getCode(),"成功!", "0");
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseResult update(@RequestBody NotifyLog1 notifyLog1) throws IOException {
        Integer code  = notifyLogService.updateAction(notifyLog1);
        return new ResponseResult(RspStatusEnum.SUCCESS.getCode(),RspStatusEnum.SUCCESS.getMessage(),code.toString());
    }

    @RequestMapping(value = "/confirm", method = RequestMethod.POST)
    public ResponseResult confirm(@RequestBody NotifyLog1 notifyLog1) throws IOException {
        Integer code  = notifyLogService.updateAction(notifyLog1);
        return new ResponseResult(RspStatusEnum.SUCCESS.getCode(),RspStatusEnum.SUCCESS.getMessage(),code.toString());
    }


    //大屏主页面柱状图报警类型数据返回
    @RequestMapping(value = "/queryTypeNum", method = RequestMethod.GET)
    public ResponseResult queryTypeNum() throws IOException {
        return new ResponseResult(RspStatusEnum.SUCCESS.getCode(),"成功", notifyLogService.queryTypeNum());
    }
}
